package com.tcd.explore.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.tcd.explore.pojo.ObjectDamageInfo;
import com.tcd.explore.service.ObjectDamageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 物损信息详情表 前端控制器
 * </p>
 *
 * @author Jarle
 * @since 2021-05-25
 */
@RestController
@CrossOrigin
@RequestMapping("/generator")
public class ObjectDamageInfoController {
    @Autowired
    ObjectDamageInfoService objectdamageinfo;

    @RequestMapping("/objectdamageInfoall")
    public List<ObjectDamageInfo> objectDamageInfoList(String claimId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("claim_mainId", claimId);
        return objectdamageinfo.list(wrapper);
    }

    @RequestMapping("/objectdamageInfoalladd")
    public Integer objectDamageInfoadd(@RequestBody ObjectDamageInfo obj) {
        Long id = IdWorker.getId();
        String num = 439 + "" + id.intValue();
        Integer i = 0;
        if (num.indexOf('-') != -1) {
            num = num.substring(0, num.lastIndexOf("-")) + num.substring(num.lastIndexOf("-") + 1, num.length() - 1);
        }
        i = Integer.parseInt(num.substring(0, 9));
        obj.setObjectDamage(Integer.parseInt(num.substring(0, 9)));
        return objectdamageinfo.save(obj) == true ? i : 0;
    }

    @RequestMapping("/objectdamagestatusedit")
    public boolean objectdamagestatusedit(String lossstatus, String claimmainid) {
        return objectdamageinfo.ObjectDamageinfoupdate(lossstatus, claimmainid);
    }

    @RequestMapping("/objectdamagedel")
    public boolean objectdamagedel(String objid) {
        return objectdamageinfo.removeById(objid);
    }

    @RequestMapping("/objectdamageedit")
    public boolean objectdamageedit(@RequestBody ObjectDamageInfo obj) {
        return objectdamageinfo.updateById(obj);
    }
}

